home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / docs / drivers.doc < prev    next >
Text File  |  1993-12-06  |  18KB  |  309 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.             Abstract
  8.  
  9.             This document  describes the  graphics driver  format used  for DJGPP and  the
  10.             LIBGRX  graphics library.  It also gives  hints for  creating a  driver for an
  11.             unsupported display adapter. 
  12.  
  13.             Introduction
  14.  
  15.             The DJGPP graphics drivers do two things:
  16.  
  17.               (1) Invoke the BIOS INT 10 routine for setting up the desired graphics mode.
  18.                   Different boards  support different  resolutions and use  different mode
  19.                   numbers -- that's why different drivers are needed for different boards.
  20.  
  21.               (2) Implement page  mapping for video modes which use more than 64K of video
  22.                   memory. This is again board dependent.
  23.  
  24.             Old driver format
  25.  
  26.             The  following C  declarations  describe the  header of  an  old format  DJGPP
  27.             graphics driver. Of course, real drivers are coded in assembly. 
  28.  
  29.             typedef unsigned short u_short;
  30.                  typedef unsigned char  u_char;
  31.  
  32.                  struct old_driver_header {
  33.                      u_short      mode_set_routine_offset;
  34.                      u_short      paging_routine_offset;
  35.                      u_short      paging_mode_flag;                          /* 0 if no separate R/W, 1 if yes */
  36.                      u_short      default_text_width;
  37.                      u_short      default_text_height;
  38.                      u_short      default_graphics_width;
  39.                      u_short      default_graphics_height;
  40.                  };
  41.  
  42.             The mode set routine does the following:
  43.  
  44.             ;--------------------------------------------------------------------------
  45.                  ; Entry: AX=mode selection
  46.                  ;                0=80x25 text
  47.                  ;                1=default text
  48.                  ;                2=text CX cols by DX rows
  49.                  ;                3=biggest text
  50.                  ;                4=320x200 graphics
  51.                  ;                5=default graphics
  52.                  ;                6=graphics CX width by DX height
  53.                  ;                7=biggest non-interlaced graphics
  54.                  ;                8=biggest graphics
  55.                  ;         CX=width (in pixels or characters) (not always used -- depends on AX)
  56.                  ;         DX=height
  57.                  ;
  58.                  ; NOTE: This runs in real mode, but don't mess with the segment registers.
  59.                  ;
  60.                  ; Exit:  CX=width (in pixels or characters)
  61.  
  62.  
  63.  
  64.  
  65.  
  66.                  ;         DX=height
  67.                  ;--------------------------------------------------------------------------
  68.  
  69.             The paging routine does the following:
  70.  
  71.             ;--------------------------------------------------------------------------
  72.                  ; Entry: AH=read page
  73.                  ;         AL=write page
  74.                  ;
  75.                  ; NOTE: This runs in protected mode!  Don't mess with the segment registers!
  76.                  ; This code must be relocatable and may not reference any data!
  77.                  ;
  78.                  ; Exit: VGA configured.
  79.                  ;        AX,BX,CX,DX,SI,DI may be trashed
  80.                  ;--------------------------------------------------------------------------
  81.  
  82.             The old style  graphics driver structure  remained unchanged for the  first 16
  83.             color drivers developed for LIBGRX. The only difference is that the additional
  84.             15  bits in the  third word of  the header were  given new meanings.  (The 256
  85.             color  DJGPP  library only  used  one  bit to  encode  the  capability to  map
  86.             different pages for  reading and writing.) The  values of these new  bitfields
  87.             were assigned as to stay compatible with the existing 256 color drivers. (I.e.
  88.             the  0  value  in every  bitfield  selects  the  256  color VGA  option.)  The
  89.             definition of these bits (from "grdriver.h"):
  90.  
  91.             #define GRD_NEW_DRIVER  0x0008             /* NEW FORMAT DRIVER IF THIS IS SET */
  92.  
  93.                  #define GRD_PAGING_MASK   0x0007           /* mask for paging modes */
  94.                  #define GRD_NO_RW         0x0000           /* standard paging, no separate R/W */
  95.                  #define GRD_RW_64K        0x0001           /* two separate 64K R/W pages */
  96.                  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  97.                  /* THE FOLLOWING THREE OPTIONS ARE NOT SUPPORTED AT THIS TIME             */
  98.                  #define GRD_RW_32K        0x0002           /* two separate 32Kb pages */
  99.                  #define GRD_MAP_128K      0x0003           /* 128Kb memory map -- some Tridents
  100.                                                                can do it (1024x768x16 without
  101.                                                                paging!!!)
  102.                  #define GRD_MAP_EXTMEM    0x0004           /* Can be mapped extended, above 1M.
  103.                                                                Some Tseng 4000-s can do it, NO
  104.                                                                PAGING AT ALL!!!! */
  105.                  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  106.  
  107.                  #define GRD_TYPE_MASK     0xf000           /* adapter type mask */
  108.                  #define GRD_VGA           0x0000           /* vga */
  109.                  #define GRD_EGA           0x1000           /* ega */
  110.                  #define GRD_HERC          0x2000           /* hercules */
  111.                  #define GRD_8514A         0x3000           /* 8514/A or compatible */
  112.                  #define GRD_S3            0x4000           /* S3 graphics accelerator */
  113.  
  114.                  #define GRD_PLANE_MASK    0x0f00           /* bitplane number mask */
  115.                  #define GRD_8_PLANES      0x0000           /* 8 planes = 256 colors */
  116.                  #define GRD_4_PLANES      0x0100           /* 4 planes = 16 colors */
  117.                  #define GRD_1_PLANE       0x0200           /* 1 plane  = 2 colors */
  118.                  #define GRD_16_PLANES     0x0300           /* VGA with 32K colors */
  119.                  #define GRD_8_X_PLANES    0x0400           /* VGA in mode X w/ 256 colors */
  120.  
  121.  
  122.  
  123.  
  124.  
  125.                  #define GRD_MEM_MASK      0x00f0           /* memory size mask */
  126.                  #define GRD_64K           0x0010           /* 64K display memory */
  127.                  #define GRD_128K          0x0020           /* 128K display memory */
  128.                  #define GRD_256K          0x0030           /* 256K display memory */
  129.                  #define GRD_512K          0x0040           /* 512K display memory */
  130.                  #define GRD_1024K         0x0050           /* 1MB display memory */
  131.                  #define GRD_192K          0x0060           /* 192K -- some 640x480 EGA-s */
  132.                  #define GRD_M_NOTSPEC     0x0000           /* memory amount not specified */
  133.  
  134.             An old style  driver has the  'GRD_NEW_DRIVER' bit cleared.  It can work  with
  135.             previous versions of GO32. Of course  for 16 color support the application has
  136.             to be  linked  with the  LIBGRX  library instead  of  the original  256  color
  137.             library.
  138.  
  139.             The following additional  old format  graphics drivers are  supplied with  the
  140.             LIBGRX graphics library:
  141.  
  142.                   EGA16.GRD         16 color EGA driver (640x350x16 max. resolution)
  143.                   VGA16.GRD         16   color  standard   VGA  driver   (640x480x16  max.
  144.                                     resolution)
  145.                   TSENG4KN.GRD      same as  DJGPP's Tseng ET  4000 256 color  driver, but
  146.                                     with  added support  for the  100x40 text  mode. (max:
  147.                                     1024x768x256)
  148.                   TSENG416.GRD      Tseng ET 4000 16 color driver. (max: 1024x768x16)
  149.                   TRID89N.GRD       Trident  8900 256  color  driver. This  driver has  an
  150.                                     updated  paging  routine  which  seems   to  fix  some
  151.                                     previous   problems  on  boards   with  recent  enough
  152.                                     chipsets. (max: 1024x768x256)
  153.                   TRID8916.GRD:     Trident 8900 16 color driver (max: 1024x768x16)
  154.  
  155.  
  156.             New driver format
  157.  
  158.             The disadvantage of the old  driver format is that the number of colors is not
  159.             programmable. The new driver format solves  this problem and it also gives the
  160.             application program a way to query the driver for a list of the supported text
  161.             and graphics modes. For this the driver header was extended as follows:
  162.  
  163.             struct new_driver_header {
  164.                      u_short      mode_set_routine_offset;
  165.                      u_short      paging_routine_offset;
  166.                      u_short      driver_mode_flag;                 /* flag word, see bits below */
  167.                      u_short      default_text_width;
  168.                      u_short      default_text_height;
  169.                      u_short      default_graphics_width;
  170.                      u_short      default_graphics_height;
  171.                      u_short      default_color_number;             /* NEW, may be set from environment */
  172.                      u_short      init_routine_offset;              /* NEW, call once after drvr loaded */
  173.                      u_short      text_mode_table_offset;           /* NEW, table of supported text modes */
  174.                      u_short      graphics_mode_table_offset;       /* NEW, table of supported graphics modes */
  175.                  };
  176.  
  177.             'text_mode_table_offset' points to a table with entries as follows:
  178.  
  179.  
  180.  
  181.  
  182.  
  183.                  struct text_mode_entry {
  184.                      u_short      columns;
  185.                      u_short      rows;
  186.                      u_short      number_of_colors;                 /* in text mode it is mainly here to make
  187.                                                                        GCC happy with the alignments */
  188.                      u_char       BIOS_mode;                        /* BIOS mode number. Mode not available on
  189.                                                                        the current card if this field is 0xff. */
  190.                      u_char       special;                          /* if non zero then the driver does some
  191.                                                                        special hacks to set it up (like
  192.                                                                        the 50 row mode on a standard VGA) */
  193.                  };
  194.  
  195.             The end of the table is marked by an all 0 entry. The table entries are sorted
  196.             by  increasing size. The field 'graphics_mode_table_offset'  points to a table
  197.             with entries as follows:
  198.  
  199.             struct graphics_mode_entry {
  200.                      u_short      width;
  201.                      u_short      height;
  202.                      u_short      number_of_colors;
  203.                      u_char       BIOS_mode;                        /* BIOS mode number. Mode not available on
  204.                                                                        the current card if this field is 0xff.
  205.                                                                        (This may happen for example if the card
  206.                                                                        is not fully populated with RAM) */
  207.                      u_char       special;                          /* if non zero then the driver does some
  208.                                                                        special hacks to set it up (like
  209.                                                                        setting up the 32768 color mode on
  210.                                                                        some ET4000 cards) */
  211.                  };
  212.  
  213.             The end  of the  table is marked  by an all  0 entry.  The table is  sorted by
  214.             increasing color number and within the same color modes by increasing size.
  215.  
  216.             If  the driver  is of  the new type  then it  also supports  an initialization
  217.             routine. This  is called once after  the driver is  loaded. The initialization
  218.             routine can do one or more of the following:
  219.  
  220.               (1) Check whether the video card is of the expected type
  221.  
  222.               (2) Determine the amount of video memory on board.
  223.  
  224.               (3) Determine which  of the modes in  the text and graphics  mode tables are
  225.                   actually available (due to  video RAM and possibly DAC  [32768 colors!!]
  226.                   limitations) and mark the unavailable entries in the tables.
  227.  
  228.             To use the new format drivers a recent version of GO32 (1.06, after the middle
  229.             of  April  1992) has  to  be  used. Such  versions  should  recognize the  "nc
  230.             <number>"  option field in the  GO32 environment variable  which specifies the
  231.             default number of colors for the driver.
  232.  
  233.             The  following new format drivers  have been included  with the LIBGRX library
  234.             (new drivers have the ".GRN" extension):
  235.  
  236.                   STDEGA.GRN        standard EGA 16 color driver
  237.  
  238.  
  239.  
  240.  
  241.  
  242.                   STDVGA.GRN        standard VGA 16 and 256 color driver
  243.                   ET4000.GRN        Tseng ET 4000 16 256 and 32768 color driver
  244.                   TR8900.GRN        Trident 8900 16 and 256 color driver
  245.                   ATIULTRA.GRN      Driver for  the ATI  ULTRA board. This  board actually
  246.                                     contains two graphics adapters: a 512 KByte SVGA board
  247.                                     and a  8514/A compatible  accelerator. The driver  was
  248.                                     programmed  to use  the VGA  part for  text,  16 color
  249.                                     graphics, and low resolution  256 color graphics modes
  250.                                     and  the 8514/A  part  for high  resolution 256  color
  251.                                     modes.  This driver  should work  with any  VGA+8514/A
  252.                                     (the  8514/A  MUST   have  1MB  memory   for  1024x768
  253.                                     resolution)  combination as  long as  the ATI-specific
  254.                                     modes of the VGA part are not used.
  255.                   STEALTH.GRN Driver  for  the  Diamond  Stealth  S3 graphics  accelerator
  256.                               board.  The driver was programmed to use VGA-style video RAM
  257.                               access  for text, 16 color  graphics, and low resolution 256
  258.                               color graphics  modes and  the S3 accelarator  functions for
  259.                               high resolution  256 color  modes. Currently no  32768 color
  260.                               modes are supported  on S3 boards.  This driver should  work
  261.                               with other S3-based boards which have a VESA BIOS.
  262.  
  263.  
  264.             Creating a driver for an unsupported board
  265.  
  266.             You can  only use EGA or  VGA boards in 16  256 or 32768 color  modes with the
  267.             graphics library. In the near future there will be support for Hercules boards
  268.             as well. SUPPORT IS NOT PLANNED FOR: BOARDS  WITH ON-BOARD GRAPHICS PROCESSORS
  269.             (TIGA, 8514A, etc...) To create a  driver for an unsupported EGA or  VGA board
  270.             you will need the followings:
  271.  
  272.               (1) An  assembler (TASM or MASM), a linker (TLINK  or LINK) and a utility to
  273.                   convert .EXE files to the .COM format (EXE2BIN). See also the 'makefile'
  274.                   in the 'drivers' sub-directory.
  275.               (2) A  documentation of the board containing the supported BIOS mode numbers
  276.                   and resolutions. 
  277.               (3) If the driver needs to support modes which use a  memory map bigger than
  278.                   64K then you also need a piece of code which does page switching on your
  279.                   board. (Any  mode above 800x600  in 16 colors  or 320x200 in  256 colors
  280.                   DOES USE paging.) Possible sources:
  281.                       - a working, tested  256 color  original DJGPP driver  (if you  just
  282.                         want to convert it to the new format).
  283.                       - VGAKIT.ZIP (available from various archive sites,  like wuarchive,
  284.                         simtel, etc...)
  285.                       - various books on the subject.
  286.  
  287.             It is best to start with the source of a driver supporting similar resolutions
  288.             as your board.  Use the proper format  driver, i.e. if  you want a new  format
  289.             driver start  with a  new original,  etc... Typically  the driver  sources are
  290.             relatively well commented. What you need to do is:
  291.  
  292.               (1) possibly change  the option word at  the head of the  driver to indicate
  293.                   the  number of colors (old format only),  the amount of memory on board,
  294.                   the memory mapping capabilities of the board. 
  295.               (2) change the mode setting code to use the proper BIOS mode numbers. In the
  296.  
  297.  
  298.  
  299.  
  300.  
  301.                   old  format drivers these are somewhat scattered throughout the code, in
  302.                   the new format drivers you need to edit a few tables only.
  303.               (3) Replace the paging routine with the one suitable for your board. If your
  304.                   driver supports 16  color resolutions  beyond 800x600 then  you have  to
  305.                   make sure that upon exit from the paging routine the graphics controller
  306.                   port's (0x3ce)  index register is reset to 8. (See the paging routine in
  307.                   "TR8900.ASM".)  If  the paging  mechanism  does  not  use  any  register
  308.                   accessed  through the graphics controller  port, then you  don't need to
  309.                   worry about this.